package com.touni.designpattern.filterpattern;

import com.touni.designpattern.filterpattern.criteria.CriteriaAge;
import com.touni.designpattern.filterpattern.criteria.CriteriaMale;

import java.util.ArrayList;
import java.util.List;

/**
 * @ClassName : FilterDemo
 * @Description :  过滤器模式
 * 允许开发人员使用不同的标准来过滤一组对象，通过逻辑运算以解耦的方式把它们连接起来。
 * 这种类型的设计模式属于结构型模式，它结合多个标准来获得单一标准。
 * @Author : lwq
 * @Date: 2020-10-30 16:57
 */
public class FilterDemo {

    public static void main(String[] args) {
        List<PersonModel> list = new ArrayList<>();
        list.add(new PersonModel("张文东1","男",36));
        list.add(new PersonModel("张文东2","女",26));
        list.add(new PersonModel("张文3","女",29));
        list.add(new PersonModel("张文东4","女",31));
        list.add(new PersonModel("张文东5","男",26));
        list.add(new PersonModel("张文东6","男",21));
        list.add(new PersonModel("张文东7","男",89));
        new AndCriteria(new CriteriaAge(),new CriteriaMale()).filterPerson(list)
                    .stream().forEach(a -> System.out.println(a));
        System.out.println("======================");
        new OrCriteria(new CriteriaAge(),new CriteriaMale()).filterPerson(list).stream()
                .forEach(a -> System.out.println(a));

    }
}
